<include file="Public:header"/>
<link rel="stylesheet" href="__CSS__/yf.css" />
<body class="J_scroll_fixed">
<div class="wrap J_check_wrap">
    <include file="Public:nav"/>
    
    <div class="J_tabs_contents">
    	<div class="yf_comment_panert" id="send_{$list.id}">
    		<p class="yf_comment_content"><span class="yf_comment_author">{$list.userid|getNickName}：</span>{$list.content}</p>
    		<span class="yf_comment_span">{$list.create_time|format_time}</span>
    		<span class="yf_comment_span"><a href="javascript:;" class="yf_comment_send yf-views" data-id="{$list.id}" data-info="{$list.infoid}" data-touser="{$list.touserid}" data-type="{$type}" data-parent="{$mid}">回复</a></span>
    		<span class="yf_comment_span"><a href="javascript:;" class="yf_comment_del yf-views" data-id="{$list.id}">删除</a></span>
    		<if condition="$list.id eq $id">
    		<div class="yf_comment_box">
    			<input type="hidden" id="infoid" value="{$list.infoid}">
    			<input type="hidden" id="touserid" value="{$list.userid}">
    			<input type="hidden" id="msgType" value="{$type}">
    			<input type="hidden" id="parent_id" value="{$mid}">
    			<textarea class="yf_comment_textarea" id="content"></textarea>
    			<button class="yf_comment_btn" data-type="yes">回复</button>
    		</div>
    		</if>
    	</div>
    	<volist name="list.childlist" id="lt">
    	<div class="yf_comment_child" id="send_{$lt.id}">
    		<p class="yf_comment_content">
    			<if condition="$lt.userid eq 0">
    		<span class="yf_comment_admin">
    			烘焙圈：
    		</span>
    			<else/>
    		<span class="yf_comment_author">
    			{$lt.userid|getNickName}：
    		</span>
    			</if>
    		<span class="yf_comment_mem">
    			<if condition="$lt.touserid eq 0">
    			@烘焙圈：
    			<else/>
    			@{$lt.touserid|getNickName}：
    			</if>
    		</span>{$lt.content}</p>
    		<span class="yf_comment_span">{$lt.create_time|format_time}</span>
    		<span class="yf_comment_span"><a href="javascript:;" class="yf_comment_send yf-views" data-id="{$lt.id}" data-info="{$lt.infoid}" data-touser="{$lt.touserid}" data-type="{$type}" data-parent="{$mid}">回复</a></span>
    		<span class="yf_comment_span"><a href="javascript:;" class="yf_comment_del yf-views" data-id="{$lt.id}">删除</a></span>
    		<if condition="$lt.id eq $id">
    		<div class="yf_comment_box">
    			<input type="hidden" id="infoid" value="{$lt.infoid}">
    			<input type="hidden" id="touserid" value="{$lt.userid}">
    			<input type="hidden" id="msgType" value="{$type}">
    			<input type="hidden" id="parent_id" value="{$mid}">
    			<textarea class="yf_comment_textarea" id="content"></textarea>
    			<button class="yf_comment_btn" data-type="yes">回复</button>
    		</div>
    		</if>
    	</div>
    	</volist>
    </div>
</div>
<script src="__JS__/common.js"></script>
<script src="__JS__/content_addtop.js"></script>
<script>
	$(function(){
		$('.yf_comment_send').click(function(e){
			e.preventDefault();
			var _this = $(this);
			$('.yf_comment_box').remove();
			var id = _this.attr('data-id');
			var infoid = _this.attr('data-info'),
				touserid = _this.attr('data-touser'),
				msgType = _this.attr('data-type'),
				parent_id = _this.attr('data-parent');
			var str = '<div class="yf_comment_box">';
				str += '<input type="hidden" id="infoid" value="' + infoid + '">';
				str += '<input type="hidden" id="touserid" value="' + touserid + '">';
				str += '<input type="hidden" id="msgType" value="' + msgType + '">';
				str += '<input type="hidden" id="parent_id" value="' + parent_id + '">';
				str += '<textarea class="yf_comment_textarea" id="content"></textarea>';
				str += '<button class="yf_comment_btn" data-type="yes">回复</button>';
				str += '</div>';
			$('#send_' + id).append(str);
		});

		$('.J_tabs_contents').on('click', '.yf_comment_btn', function(e){
			e.preventDefault();
			var _this = $(this);
			var temp_type = _this.attr('data-type');
			if(temp_type == 'yes')
			{
				var infoid = $('#infoid').val(),
					touserid = $('#touserid').val(),
					type = $('#msgType').val(),
					parent_id = $('#parent_id').val(),
					content = $('#content').val();
				var num = 5;
		        if ($('#content').val().length < num) 
			    {
		            alert('回复内容不能少于'+num+'个字');
		            return false;
		        }
		        _this.attr('data-type', 'no');
		        $.ajax({
					type: "POST",
					global: false,
					url: "/index.php?m=Admins&c=User&a=yf_replymsg",
					data: {
						infoid: infoid,
						touserid: touserid,
						type: type,
						parent_id: parent_id,
						content: content
					},
					dataType: 'json',
					success: function(data){
						if(data.status == 1)
						{
							alert(data.info);
							location.reload();
						}
						else
						{
							alert(data.info);
						}
						_this.attr('data-type', 'yes');
					},
					error: function(){
						alert("数据执行错误！");
		                return false;
					}
			    });
			}
			else
			{
				alert("回复中,请稍后");
			}
		});

		$('.yf_comment_del').click(function(e){
			e.preventDefault();
			var id = $(this).attr('data-id');
			if(confirm("确定删除该评论么？"))
			{
				$.ajax({
					type: "POST",
					global: false,
					url: "/index.php?m=Admins&c=User&a=message_deleteAll",
					data: {
						ids: id
					},
					dataType: 'json',
					success: function(data){
						if(data.status == 1)
						{
							alert(data.info);
							location.href = data.url;
						}
						else
						{
							alert(data.info);
						}
					},
					error: function(){
						alert("数据执行错误！");
		                return false;
					}
				});
			}
		});
	});
</script>
</body>
</html>